/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.tutorial.model;

import com.wisnu.tutorial.object.MahasiswaObject;
import com.wisnu.tutorial.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Wisnu Wardoyo
 */
public class MahasiswaReader {

    Connection connection;
    List<MahasiswaObject> mahasiswa = new ArrayList<>();

    public boolean checkData() {
        Statement stmt;
        try {
            stmt = connection.getCon().createStatement();
            ResultSet resultSet = stmt.executeQuery("SELECT * FROM `mahasiswa`");
            while (resultSet.next()) {
                MahasiswaObject object = new MahasiswaObject();
                object.setNim(resultSet.getString("nim"));
                object.setNama(resultSet.getString("nama"));
                object.setProdi(resultSet.getString("prodi"));
                object.setFakultas(resultSet.getString("fakultas"));
                object.setAlamat(resultSet.getString("alamat"));
                object.setTempatLahir(resultSet.getString("tempat_lahir"));
                object.setTanggalLahir(resultSet.getString("tanggal_lahir"));
                object.setSex(resultSet.getString("sex"));
                object.setTelp(resultSet.getString("telp"));
                object.setGolonganDarah(resultSet.getString("goldar"));
                object.setEmail(resultSet.getString("email"));
                object.setUsername(resultSet.getString("username"));
                mahasiswa.add(object);
            }
            stmt.close();
            return true;
        } catch (SQLException ex) {
            System.err.println(ex);
            return false;
        }
    }

    public void setConnection(Connection connection) {
        this.connection = connection;
    }

    public List<MahasiswaObject> getDataMahasiswa() {
        return mahasiswa;
    }
    
    
    
}
